home *** CD-ROM | disk | FTP | other *** search
/ Micromanía: 150 Juegos 2010 / 150Juegos_16.iso / Shareware / Shape Smash / shape-smash.swf / scripts / mx / core / Application.as next >
Encoding:
Text File  |  2010-05-14  |  21.3 KB  |  681 lines

  1. package mx.core
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.events.ContextMenuEvent;
  5.    import flash.events.Event;
  6.    import flash.external.ExternalInterface;
  7.    import flash.net.URLRequest;
  8.    import flash.net.navigateToURL;
  9.    import flash.system.ApplicationDomain;
  10.    import flash.system.Capabilities;
  11.    import flash.ui.ContextMenu;
  12.    import flash.ui.ContextMenuItem;
  13.    import flash.utils.setInterval;
  14.    import mx.containers.utilityClasses.ApplicationLayout;
  15.    import mx.effects.EffectManager;
  16.    import mx.events.FlexEvent;
  17.    import mx.managers.FocusManager;
  18.    import mx.managers.ILayoutManager;
  19.    import mx.managers.ISystemManager;
  20.    import mx.resources.ResourceBundle;
  21.    import mx.styles.CSSStyleDeclaration;
  22.    import mx.styles.IStyleClient;
  23.    import mx.styles.StyleManager;
  24.    
  25.    use namespace mx_internal;
  26.    
  27.    public class Application extends LayoutContainer
  28.    {
  29.       private static var viewSourceMenuItem:String;
  30.       
  31.       mx_internal static const VERSION:String = "2.0.1.0";
  32.       
  33.       private static var packageResources:ResourceBundle = ResourceBundle.getResourceBundle("core",ApplicationDomain.currentDomain);
  34.       
  35.       mx_internal static var useProgressiveLayout:Boolean = false;
  36.       
  37.       loadResources();
  38.       
  39.       public var frameRate:Number;
  40.       
  41.       private var _viewSourceURL:String;
  42.       
  43.       public var scriptTimeLimit:Number;
  44.       
  45.       public var resetHistory:Boolean = true;
  46.       
  47.       mx_internal var _url:String;
  48.       
  49.       public var preloader:Object;
  50.       
  51.       public var pageTitle:String;
  52.       
  53.       private var processingCreationQueue:Boolean = false;
  54.       
  55.       private var creationQueue:Array;
  56.       
  57.       private var resizeWidth:Boolean = true;
  58.       
  59.       public var controlBar:IUIComponent;
  60.       
  61.       private var _applicationViewMetrics:EdgeMetrics;
  62.       
  63.       private var preloadObj:Object;
  64.       
  65.       public var usePreloader:Boolean;
  66.       
  67.       private var resizeHandlerAdded:Boolean = false;
  68.       
  69.       private var resizeHeight:Boolean = true;
  70.       
  71.       public var scriptRecursionLimit:int;
  72.       
  73.       mx_internal var _parameters:Object;
  74.       
  75.       public function Application()
  76.       {
  77.          resizeHandlerAdded = false;
  78.          creationQueue = [];
  79.          processingCreationQueue = false;
  80.          resizeWidth = true;
  81.          resizeHeight = true;
  82.          resetHistory = true;
  83.          name = "application";
  84.          UIComponentGlobals.mx_internal::layoutManager = Singleton.getInstance("mx.managers::ILayoutManager") as ILayoutManager;
  85.          UIComponentGlobals.mx_internal::layoutManager.usePhasedInstantiation = true;
  86.          if(!ApplicationGlobals.application)
  87.          {
  88.             ApplicationGlobals.application = this;
  89.          }
  90.          super();
  91.          layoutObject = new ApplicationLayout();
  92.          layoutObject.target = this;
  93.          boxLayoutClass = ApplicationLayout;
  94.          showInAutomationHierarchy = true;
  95.       }
  96.       
  97.       private static function loadResources() : void
  98.       {
  99.          viewSourceMenuItem = packageResources.getString("viewSource");
  100.       }
  101.       
  102.       public static function get application() : Object
  103.       {
  104.          return ApplicationGlobals.application;
  105.       }
  106.       
  107.       mx_internal function dockControlBar(param1:IUIComponent, param2:Boolean) : void
  108.       {
  109.          var controlBar:IUIComponent = param1;
  110.          var dock:Boolean = param2;
  111.          if(dock)
  112.          {
  113.             try
  114.             {
  115.                removeChild(DisplayObject(controlBar));
  116.             }
  117.             catch(e:Error)
  118.             {
  119.                return;
  120.             }
  121.             rawChildren.addChildAt(DisplayObject(controlBar),mx_internal::firstChildIndex);
  122.             setControlBar(controlBar);
  123.          }
  124.          else
  125.          {
  126.             try
  127.             {
  128.                rawChildren.removeChild(DisplayObject(controlBar));
  129.             }
  130.             catch(e:Error)
  131.             {
  132.                return;
  133.             }
  134.             setControlBar(null);
  135.             addChildAt(DisplayObject(controlBar),0);
  136.          }
  137.       }
  138.       
  139.       override mx_internal function initThemeColor() : Boolean
  140.       {
  141.          var _loc1_:Boolean = false;
  142.          var _loc2_:Object = null;
  143.          var _loc3_:Number = NaN;
  144.          var _loc4_:Number = NaN;
  145.          var _loc5_:CSSStyleDeclaration = null;
  146.          _loc1_ = super.mx_internal::initThemeColor();
  147.          if(!_loc1_)
  148.          {
  149.             _loc5_ = StyleManager.getStyleDeclaration("global");
  150.             if(_loc5_)
  151.             {
  152.                _loc2_ = _loc5_.getStyle("themeColor");
  153.                _loc3_ = _loc5_.getStyle("rollOverColor");
  154.                _loc4_ = _loc5_.getStyle("selectionColor");
  155.             }
  156.             if(_loc2_ && isNaN(_loc3_) && isNaN(_loc4_))
  157.             {
  158.                mx_internal::setThemeColor(_loc2_);
  159.             }
  160.             _loc1_ = true;
  161.          }
  162.          return _loc1_;
  163.       }
  164.       
  165.       private function resizeHandler(param1:Event) : void
  166.       {
  167.          var _loc2_:Number = NaN;
  168.          var _loc3_:Number = NaN;
  169.          if(resizeWidth)
  170.          {
  171.             if(isNaN(percentWidth))
  172.             {
  173.                _loc2_ = DisplayObject(systemManager).width;
  174.             }
  175.             else
  176.             {
  177.                super.percentWidth = Math.max(percentWidth,0);
  178.                super.percentWidth = Math.min(percentWidth,100);
  179.                _loc2_ = percentWidth * screen.width / 100;
  180.             }
  181.             if(!isNaN(explicitMaxWidth))
  182.             {
  183.                _loc2_ = Math.min(_loc2_,explicitMaxWidth);
  184.             }
  185.             if(!isNaN(explicitMinWidth))
  186.             {
  187.                _loc2_ = Math.max(_loc2_,explicitMinWidth);
  188.             }
  189.          }
  190.          else
  191.          {
  192.             _loc2_ = width;
  193.          }
  194.          if(resizeHeight)
  195.          {
  196.             if(isNaN(percentHeight))
  197.             {
  198.                _loc3_ = DisplayObject(systemManager).height;
  199.             }
  200.             else
  201.             {
  202.                super.percentHeight = Math.max(percentHeight,0);
  203.                super.percentHeight = Math.min(percentHeight,100);
  204.                _loc3_ = percentHeight * screen.height / 100;
  205.             }
  206.             if(!isNaN(explicitMaxHeight))
  207.             {
  208.                _loc3_ = Math.min(_loc3_,explicitMaxHeight);
  209.             }
  210.             if(!isNaN(explicitMinHeight))
  211.             {
  212.                _loc3_ = Math.max(_loc3_,explicitMinHeight);
  213.             }
  214.          }
  215.          else
  216.          {
  217.             _loc3_ = height;
  218.          }
  219.          if(_loc2_ != width || _loc3_ != height)
  220.          {
  221.             invalidateProperties();
  222.             invalidateSize();
  223.          }
  224.          setActualSize(_loc2_,_loc3_);
  225.          invalidateDisplayList();
  226.       }
  227.       
  228.       override public function set tabIndex(param1:int) : void
  229.       {
  230.       }
  231.       
  232.       public function set viewSourceURL(param1:String) : void
  233.       {
  234.          _viewSourceURL = param1;
  235.       }
  236.       
  237.       override mx_internal function get usePadding() : Boolean
  238.       {
  239.          return layout != ContainerLayout.ABSOLUTE;
  240.       }
  241.       
  242.       private function initContextMenu() : void
  243.       {
  244.          var _loc1_:ContextMenu = null;
  245.          var _loc2_:ContextMenuItem = null;
  246.          _loc1_ = new ContextMenu();
  247.          _loc1_.hideBuiltInItems();
  248.          _loc1_.builtInItems.print = true;
  249.          if(_viewSourceURL)
  250.          {
  251.             _loc2_ = new ContextMenuItem(viewSourceMenuItem,true);
  252.             _loc2_.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemSelectHandler);
  253.             _loc1_.customItems.push(_loc2_);
  254.          }
  255.          contextMenu = _loc1_;
  256.       }
  257.       
  258.       override public function set icon(param1:Class) : void
  259.       {
  260.       }
  261.       
  262.       override public function set percentWidth(param1:Number) : void
  263.       {
  264.          super.percentWidth = param1;
  265.          invalidateDisplayList();
  266.       }
  267.       
  268.       override public function getChildIndex(param1:DisplayObject) : int
  269.       {
  270.          if(Boolean(controlBar) && param1 == controlBar)
  271.          {
  272.             return -1;
  273.          }
  274.          return super.getChildIndex(param1);
  275.       }
  276.       
  277.       override public function get id() : String
  278.       {
  279.          if(!super.id && this == Application.application && ExternalInterface.available)
  280.          {
  281.             return ExternalInterface.objectID;
  282.          }
  283.          return super.id;
  284.       }
  285.       
  286.       override protected function measure() : void
  287.       {
  288.          var _loc1_:EdgeMetrics = null;
  289.          var _loc2_:Number = NaN;
  290.          super.measure();
  291.          _loc1_ = borderMetrics;
  292.          if(Boolean(controlBar) && controlBar.includeInLayout)
  293.          {
  294.             _loc2_ = controlBar.getExplicitOrMeasuredWidth() + _loc1_.left + _loc1_.right;
  295.             measuredWidth = Math.max(measuredWidth,_loc2_);
  296.             measuredMinWidth = Math.max(measuredMinWidth,_loc2_);
  297.          }
  298.       }
  299.       
  300.       public function get url() : String
  301.       {
  302.          return mx_internal::_url;
  303.       }
  304.       
  305.       private function debugTickler() : void
  306.       {
  307.          var _loc1_:int = 0;
  308.          _loc1_ = 0;
  309.       }
  310.       
  311.       override public function finishPrint(param1:Object, param2:IFlexDisplayObject) : void
  312.       {
  313.          if(param2 == this)
  314.          {
  315.             setActualSize(param1.width,param1.height);
  316.             if(horizontalScrollBar)
  317.             {
  318.                horizontalScrollBar.visible = param1.horizontalScrollBarVisible;
  319.             }
  320.             if(verticalScrollBar)
  321.             {
  322.                verticalScrollBar.visible = param1.verticalScrollBarVisible;
  323.             }
  324.             if(whiteBox)
  325.             {
  326.                whiteBox.visible = param1.whiteBoxVisible;
  327.             }
  328.             horizontalScrollPosition = param1.horizontalScrollPosition;
  329.             verticalScrollPosition = param1.verticalScrollPosition;
  330.             updateDisplayList(unscaledWidth,unscaledHeight);
  331.          }
  332.          super.finishPrint(param1.scrollRect,param2);
  333.       }
  334.       
  335.       override public function set label(param1:String) : void
  336.       {
  337.       }
  338.       
  339.       public function get parameters() : Object
  340.       {
  341.          return mx_internal::_parameters;
  342.       }
  343.       
  344.       override public function prepareToPrint(param1:IFlexDisplayObject) : Object
  345.       {
  346.          var _loc2_:Object = null;
  347.          _loc2_ = {};
  348.          if(param1 == this)
  349.          {
  350.             _loc2_.width = width;
  351.             _loc2_.height = height;
  352.             _loc2_.verticalScrollPosition = verticalScrollPosition;
  353.             _loc2_.horizontalScrollPosition = horizontalScrollPosition;
  354.             _loc2_.horizontalScrollBarVisible = horizontalScrollBar != null;
  355.             _loc2_.verticalScrollBarVisible = verticalScrollBar != null;
  356.             _loc2_.whiteBoxVisible = whiteBox != null;
  357.             setActualSize(measuredWidth,measuredHeight);
  358.             horizontalScrollPosition = 0;
  359.             verticalScrollPosition = 0;
  360.             if(horizontalScrollBar)
  361.             {
  362.                horizontalScrollBar.visible = false;
  363.             }
  364.             if(verticalScrollBar)
  365.             {
  366.                verticalScrollBar.visible = false;
  367.             }
  368.             if(whiteBox)
  369.             {
  370.                whiteBox.visible = false;
  371.             }
  372.             updateDisplayList(unscaledWidth,unscaledHeight);
  373.          }
  374.          _loc2_.scrollRect = super.prepareToPrint(param1);
  375.          return _loc2_;
  376.       }
  377.       
  378.       public function get viewSourceURL() : String
  379.       {
  380.          return _viewSourceURL;
  381.       }
  382.       
  383.       override protected function layoutChrome(param1:Number, param2:Number) : void
  384.       {
  385.          var _loc3_:EdgeMetrics = null;
  386.          var _loc4_:Number = NaN;
  387.          var _loc5_:EdgeMetrics = null;
  388.          super.layoutChrome(param1,param2);
  389.          if(!mx_internal::doingLayout)
  390.          {
  391.             createBorder();
  392.          }
  393.          _loc3_ = borderMetrics;
  394.          _loc4_ = getStyle("borderThickness");
  395.          _loc5_ = new EdgeMetrics();
  396.          _loc5_.left = _loc3_.left - _loc4_;
  397.          _loc5_.top = _loc3_.top - _loc4_;
  398.          _loc5_.right = _loc3_.right - _loc4_;
  399.          _loc5_.bottom = _loc3_.bottom - _loc4_;
  400.          if(Boolean(controlBar) && controlBar.includeInLayout)
  401.          {
  402.             if(controlBar is IInvalidating)
  403.             {
  404.                IInvalidating(controlBar).invalidateDisplayList();
  405.             }
  406.             controlBar.setActualSize(width - (_loc5_.left + _loc5_.right),controlBar.getExplicitOrMeasuredHeight());
  407.             controlBar.move(_loc5_.left,_loc5_.top);
  408.          }
  409.       }
  410.       
  411.       override public function get viewMetrics() : EdgeMetrics
  412.       {
  413.          var _loc1_:EdgeMetrics = null;
  414.          var _loc2_:EdgeMetrics = null;
  415.          var _loc3_:Number = NaN;
  416.          if(!_applicationViewMetrics)
  417.          {
  418.             _applicationViewMetrics = new EdgeMetrics();
  419.          }
  420.          _loc1_ = _applicationViewMetrics;
  421.          _loc2_ = super.viewMetrics;
  422.          _loc3_ = getStyle("borderThickness");
  423.          _loc1_.left = _loc2_.left;
  424.          _loc1_.top = _loc2_.top;
  425.          _loc1_.right = _loc2_.right;
  426.          _loc1_.bottom = _loc2_.bottom;
  427.          if(Boolean(controlBar) && controlBar.includeInLayout)
  428.          {
  429.             _loc1_.top -= _loc3_;
  430.             _loc1_.top += Math.max(controlBar.getExplicitOrMeasuredHeight(),_loc3_);
  431.          }
  432.          return _loc1_;
  433.       }
  434.       
  435.       private function addedHandler(param1:Event) : void
  436.       {
  437.          if(param1.target == this && creationQueue.length > 0)
  438.          {
  439.             doNextQueueItem();
  440.          }
  441.       }
  442.       
  443.       private function menuItemSelectHandler(param1:Event) : void
  444.       {
  445.          navigateToURL(new URLRequest(_viewSourceURL),"_blank");
  446.       }
  447.       
  448.       private function doNextQueueItem(param1:FlexEvent = null) : void
  449.       {
  450.          processingCreationQueue = true;
  451.          Application.mx_internal::useProgressiveLayout = true;
  452.          callLater(processNextQueueItem);
  453.       }
  454.       
  455.       private function setControlBar(param1:IUIComponent) : void
  456.       {
  457.          if(param1 == controlBar)
  458.          {
  459.             return;
  460.          }
  461.          if(Boolean(controlBar) && controlBar is IStyleClient)
  462.          {
  463.             IStyleClient(controlBar).clearStyle("cornerRadius");
  464.             IStyleClient(controlBar).clearStyle("docked");
  465.          }
  466.          controlBar = param1;
  467.          if(Boolean(controlBar) && controlBar is IStyleClient)
  468.          {
  469.             IStyleClient(controlBar).setStyle("cornerRadius",0);
  470.             IStyleClient(controlBar).setStyle("docked",true);
  471.          }
  472.          invalidateSize();
  473.          invalidateDisplayList();
  474.          mx_internal::invalidateViewMetricsAndPadding();
  475.       }
  476.       
  477.       override public function initialize() : void
  478.       {
  479.          var _loc1_:ISystemManager = null;
  480.          var _loc2_:Object = null;
  481.          _loc1_ = systemManager;
  482.          mx_internal::_url = _loc1_.loaderInfo.url;
  483.          mx_internal::_parameters = _loc1_.loaderInfo.parameters;
  484.          initManagers(_loc1_);
  485.          mx_internal::_descriptor = null;
  486.          if(mx_internal::documentDescriptor)
  487.          {
  488.             creationPolicy == mx_internal::documentDescriptor.properties.creationPolicy;
  489.             if(creationPolicy == null || creationPolicy.length == 0)
  490.             {
  491.                creationPolicy = ContainerCreationPolicy.AUTO;
  492.             }
  493.             _loc2_ = mx_internal::documentDescriptor.properties;
  494.             if(_loc2_.width != null)
  495.             {
  496.                width = _loc2_.width;
  497.                delete _loc2_.width;
  498.             }
  499.             if(_loc2_.height != null)
  500.             {
  501.                height = _loc2_.height;
  502.                delete _loc2_.height;
  503.             }
  504.             mx_internal::documentDescriptor.events = null;
  505.          }
  506.          initContextMenu();
  507.          super.initialize();
  508.          addEventListener(Event.ADDED,addedHandler);
  509.          if(_loc1_.isTopLevel() && Capabilities.isDebugger == true)
  510.          {
  511.             setInterval(debugTickler,1500);
  512.          }
  513.       }
  514.       
  515.       private function initManagers(param1:ISystemManager) : void
  516.       {
  517.          if(param1.isTopLevel())
  518.          {
  519.             focusManager = new FocusManager(this);
  520.             param1.activate(this);
  521.          }
  522.       }
  523.       
  524.       override public function set percentHeight(param1:Number) : void
  525.       {
  526.          super.percentHeight = param1;
  527.          invalidateDisplayList();
  528.       }
  529.       
  530.       private function printCreationQueue() : void
  531.       {
  532.          var _loc1_:String = null;
  533.          var _loc2_:Number = NaN;
  534.          var _loc3_:int = 0;
  535.          var _loc4_:Object = null;
  536.          _loc1_ = "";
  537.          _loc2_ = creationQueue.length;
  538.          _loc3_ = 0;
  539.          while(_loc3_ < _loc2_)
  540.          {
  541.             _loc4_ = creationQueue[_loc3_];
  542.             _loc1_ += " [" + _loc3_ + "] " + _loc4_.id + " " + _loc4_.index;
  543.             _loc3_++;
  544.          }
  545.       }
  546.       
  547.       override public function set toolTip(param1:String) : void
  548.       {
  549.       }
  550.       
  551.       override public function styleChanged(param1:String) : void
  552.       {
  553.          super.styleChanged(param1);
  554.          if(param1 == "backgroundColor" && getStyle("backgroundImage") == getStyle("defaultBackgroundImage"))
  555.          {
  556.             clearStyle("backgroundImage");
  557.          }
  558.       }
  559.       
  560.       private function processNextQueueItem() : void
  561.       {
  562.          var queueItem:Object = null;
  563.          var nextChild:IUIComponent = null;
  564.          if(EffectManager.mx_internal::effectsPlaying.length > 0)
  565.          {
  566.             callLater(processNextQueueItem);
  567.          }
  568.          else if(creationQueue.length > 0)
  569.          {
  570.             queueItem = creationQueue.shift();
  571.             try
  572.             {
  573.                nextChild = queueItem.id is String ? document[queueItem.id] : queueItem.id;
  574.                if(nextChild is Container)
  575.                {
  576.                   Container(nextChild).createComponentsFromDescriptors(true);
  577.                }
  578.                if(nextChild is Container && Container(nextChild).creationPolicy == ContainerCreationPolicy.QUEUED)
  579.                {
  580.                   doNextQueueItem();
  581.                }
  582.                else
  583.                {
  584.                   nextChild.addEventListener("childrenCreationComplete",doNextQueueItem);
  585.                }
  586.             }
  587.             catch(e:Error)
  588.             {
  589.                processNextQueueItem();
  590.             }
  591.          }
  592.          else
  593.          {
  594.             processingCreationQueue = false;
  595.             Application.mx_internal::useProgressiveLayout = false;
  596.          }
  597.       }
  598.       
  599.       public function addToCreationQueue(param1:Object, param2:int = -1, param3:Function = null, param4:IFlexDisplayObject = null) : void
  600.       {
  601.          var _loc5_:int = 0;
  602.          var _loc6_:Object = null;
  603.          var _loc7_:Boolean = false;
  604.          var _loc8_:int = 0;
  605.          var _loc9_:int = 0;
  606.          var _loc10_:int = 0;
  607.          var _loc11_:int = 0;
  608.          var _loc12_:int = 0;
  609.          _loc5_ = int(creationQueue.length);
  610.          _loc6_ = {};
  611.          _loc7_ = false;
  612.          _loc6_.id = param1;
  613.          _loc6_.parent = param4;
  614.          _loc6_.callbackFunc = param3;
  615.          _loc6_.index = param2;
  616.          _loc11_ = 0;
  617.          while(_loc11_ < _loc5_)
  618.          {
  619.             _loc9_ = int(creationQueue[_loc11_].index);
  620.             _loc10_ = !!creationQueue[_loc11_].parent ? int(creationQueue[_loc11_].parent.nestLevel) : 0;
  621.             if(_loc6_.index != -1)
  622.             {
  623.                if(_loc9_ == -1 || _loc6_.index < _loc9_)
  624.                {
  625.                   _loc8_ = _loc11_;
  626.                   _loc7_ = true;
  627.                   break;
  628.                }
  629.             }
  630.             else
  631.             {
  632.                _loc12_ = !!_loc6_.parent ? int(_loc6_.parent.nestLevel) : 0;
  633.                if(_loc9_ == -1 && _loc10_ < _loc12_)
  634.                {
  635.                   _loc8_ = _loc11_;
  636.                   _loc7_ = true;
  637.                   break;
  638.                }
  639.             }
  640.             _loc11_++;
  641.          }
  642.          if(!_loc7_)
  643.          {
  644.             creationQueue.push(_loc6_);
  645.             _loc7_ = true;
  646.          }
  647.          else
  648.          {
  649.             creationQueue.splice(_loc8_,0,_loc6_);
  650.          }
  651.          if(initialized && !processingCreationQueue)
  652.          {
  653.             doNextQueueItem();
  654.          }
  655.       }
  656.       
  657.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  658.       {
  659.          super.updateDisplayList(param1,param2);
  660.          resizeWidth = isNaN(explicitWidth);
  661.          resizeHeight = isNaN(explicitHeight);
  662.          if(resizeWidth || resizeHeight)
  663.          {
  664.             resizeHandler(new Event(Event.RESIZE));
  665.             if(!resizeHandlerAdded)
  666.             {
  667.                systemManager.addEventListener(Event.RESIZE,resizeHandler,false,0,true);
  668.                resizeHandlerAdded = true;
  669.             }
  670.          }
  671.          else if(resizeHandlerAdded)
  672.          {
  673.             systemManager.removeEventListener(Event.RESIZE,resizeHandler);
  674.             resizeHandlerAdded = false;
  675.          }
  676.          createBorder();
  677.       }
  678.    }
  679. }
  680.  
  681.